<html>
<head><meta charset="utf-8"><title>Better error message heuristics in  #71827 · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html">Better error message heuristics in  #71827</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="221308388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/221308388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#221308388">(Dec 31 2020 at 18:39)</a>:</h4>
<p>Hi all!</p>
<p>Earlier this year I got a PR up with the heavy lifting for some improved error messages with mismatched arguments, but got stuck because I didn't know how to generate the error messages effectively, and I forgot about it for a few months.  Last night I went through the effort of rebasing onto master, would anyone be willing to answer some questions so I can start wrapping it up?</p>
<p><a href="https://github.com/rust-lang/rust/pull/71827">https://github.com/rust-lang/rust/pull/71827</a></p>
<p>Most relevantly:</p>
<ul>
<li>Given a <code>Ty</code>, is there a canonical way to get a human readable string for it for error messages?</li>
<li>Given a span, are there utilities for manipulating them? I've been grabbing the hi/lo BytePos, casting it to u32, doing some math, and constructing a new span, and this is awkward.</li>
</ul>



<a name="221309046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/221309046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#221309046">(Dec 31 2020 at 18:50)</a>:</h4>
<blockquote>
<p>Given a Ty, is there a canonical way to get a human readable string for it for error messages?</p>
</blockquote>
<p>I think just <code>println!("{}", ty)</code> should work. You can customize the display using the functions in <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/print/pretty/">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/print/pretty/</a>.</p>
<blockquote>
<p>Given a span, are there utilities for manipulating them? I've been grabbing the hi/lo BytePos, casting it to u32, doing some math, and constructing a new span, and this is awkward.</p>
</blockquote>
<p>maybe <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html#method.with_hi">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html#method.with_hi</a> and <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html#method.with_lo">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html#method.with_lo</a> ?</p>



<a name="221309374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/221309374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#221309374">(Dec 31 2020 at 18:56)</a>:</h4>
<blockquote>
<p>I have a span for the whole function definition, any tips for shrinking that to just cover the method name?</p>
</blockquote>
<p>I don't know where you got the span from, but by default <code>.span()</code> only gives you the method name. There's a function <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.span_with_body"><code>span_with_body</code></a> that has the behavior you describe.</p>



<a name="221309536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/221309536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#221309536">(Dec 31 2020 at 18:59)</a>:</h4>
<blockquote>
<p>Given a span, how can I get the code snippet for that span? for things like the expression reordered</p>
</blockquote>
<p>Maybe <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/source_map/struct.SourceMap.html#method.span_to_string"><code>span_to_string</code></a>?</p>



<a name="221309548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/221309548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#221309548">(Dec 31 2020 at 18:59)</a>:</h4>
<p><span class="user-mention" data-user-id="328499">@Pi Lanningham</span> ^</p>



<a name="221312653"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/221312653" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#221312653">(Dec 31 2020 at 19:56)</a>:</h4>
<p>Oo, thanks so much for your response!</p>
<blockquote>
<p>I think just println!(...) should work</p>
</blockquote>
<p>Oh, and I assume format! will do the same thing?  I would have thought I'd tried this back in may, but I understand rust a lot better now so I guess I just missed it.</p>
<blockquote>
<p>with_hi / with_lo</p>
</blockquote>
<p>those don't look particularly helpful, since BytePos doesn't implement mathematical operators, so I still have to cast out into u32.  I was hoping there were <code>widen_by(lo_delta, hi_delta)</code> and <code>shrink_by(lo_delta, hi_delta)</code> functions, or something similar.</p>
<blockquote>
<p>function name span</p>
</blockquote>
<p>The function name bit isn't really necessary anymore; at the time I wrote the PR, the function span was passed in, and it covered the whole function signature.  Since I wrote this PR, someone refactored the function and they now pass in a DefId instead of a span, so I can just use that directly.</p>
<blockquote>
<p>span_to_string</p>
</blockquote>
<p>Any idea what the difference between span_to_string and span_to_snippet are?</p>



<a name="221424024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/221424024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#221424024">(Jan 02 2021 at 23:52)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> ^ <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="221424137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/221424137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#221424137">(Jan 02 2021 at 23:56)</a>:</h4>
<blockquote>
<p>those don't look particularly helpful, since BytePos doesn't implement mathematical operators</p>
</blockquote>
<p><code>BytePos</code> does implement <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.BytePos.html#impl-Add%3CBytePos%3E-1"><code>+</code></a> and <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.BytePos.html#impl-Sub%3CBytePos%3E-1"><code>-</code></a> though</p>
<blockquote>
<p>Any idea what the difference between span_to_string and span_to_snippet are?</p>
</blockquote>
<p><code>span_to_string</code> gives you:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="fm">format!</span><span class="p">(</span><span class="w"></span>
<span class="w">    </span><span class="s">"{}:{}:{}: {}:{}"</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">lo</span><span class="p">.</span><span class="n">file</span><span class="p">.</span><span class="n">name</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">lo</span><span class="p">.</span><span class="n">line</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">lo</span><span class="p">.</span><span class="n">col</span><span class="p">.</span><span class="n">to_usize</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">hi</span><span class="p">.</span><span class="n">line</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">hi</span><span class="p">.</span><span class="n">col</span><span class="p">.</span><span class="n">to_usize</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"></span>
<span class="p">)</span><span class="w"></span>
</code></pre></div>
<p>which is probably not what you want. If you want the source code, use <code>span_to_snippet</code>.</p>



<a name="221424755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/221424755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#221424755">(Jan 03 2021 at 00:14)</a>:</h4>
<p>Wait they do? <span aria-label="weary" class="emoji emoji-1f629" role="img" title="weary">:weary:</span> how'd I miss that lol.  Alright, thanks! I should be able to make some significant progress on this PR now</p>



<a name="221425036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/221425036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#221425036">(Jan 03 2021 at 00:23)</a>:</h4>
<p>I think back in May, I didn't have a great Rust dev environment, and the long turnaround times on compiles on my laptop left me confused about what worked and what didn't or something</p>



<a name="222588591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222588591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222588591">(Jan 13 2021 at 14:39)</a>:</h4>
<p>If you're curious, I pushed to this PR with type interpolation based on the feedback you two provided! There's still some to work out (heuristics on when to show the new error message, vs when the old one is more understandable, and some fiddly span-math to line things up better.</p>
<p>As a preview of what the error messages look like, I create some simple examples in <code>src/test/ui/argument-suggestions/basic.stderr</code>.  I'll bless the rest of the tests once I have something closer to a finished product.</p>
<p>CC <span class="user-mention" data-user-id="255061">@Léo Lanteri Thauvin</span> <span class="user-mention" data-user-id="232545">@Joshua Nelson</span></p>



<a name="222589130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222589130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222589130">(Jan 13 2021 at 14:42)</a>:</h4>
<p><span class="user-mention" data-user-id="328499">@Pi Lanningham</span> wow, that help message is so awesome :D it's like magic</p>



<a name="222589220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222589220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222589220">(Jan 13 2021 at 14:43)</a>:</h4>
<p>I'm really proud of the algorithm haha.  It's like a hybrid of levenstein distance and longest common subsequence.</p>



<a name="222589478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222589478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222589478">(Jan 13 2021 at 14:45)</a>:</h4>
<p>now I need to read the code haha</p>



<a name="222590366"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222590366" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222590366">(Jan 13 2021 at 14:50)</a>:</h4>
<p>wow you even have super detailed comments :D</p>



<a name="222591655"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222591655" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222591655">(Jan 13 2021 at 14:58)</a>:</h4>
<p>I get made fun of for that at work haha</p>



<a name="222592255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222592255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222592255">(Jan 13 2021 at 15:01)</a>:</h4>
<p>nah it's super helpful here, I don't know any of the compiler APIs</p>



<a name="222592270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222592270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222592270">(Jan 13 2021 at 15:01)</a>:</h4>
<p>well, not for type checking anyway</p>



<a name="222594226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222594226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222594226">(Jan 13 2021 at 15:12)</a>:</h4>
<p>left a review :)</p>



<a name="222600776"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222600776" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222600776">(Jan 13 2021 at 15:48)</a>:</h4>
<p>Thanks for the review!  I'll get the suggested changes in after work.  (Some of it I already planned to work on, but lots of them weren't, so super useful).  Do you have any tips for working with spans? all this fiddly comma/newline/spaces work is going to be the worst part.</p>



<a name="222600897"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222600897" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222600897">(Jan 13 2021 at 15:49)</a>:</h4>
<p>I have not worked with spans a lot unfortunately, <span class="user-mention silent" data-user-id="119031">Esteban Küber</span> may have more suggestions</p>



<a name="222600933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222600933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222600933">(Jan 13 2021 at 15:49)</a>:</h4>
<p>but I would suggest <em>not</em> trying to look at the source code and just highlight the argument itself</p>



<a name="222600971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222600971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222600971">(Jan 13 2021 at 15:49)</a>:</h4>
<p>otherwise you'll just keep hitting more and more edge cases with weird formatting</p>



<a name="222601314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222601314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222601314">(Jan 13 2021 at 15:51)</a>:</h4>
<p>yea, generally that's what I do, but for <code>Missing</code>, I need to identify where to place the new arguments, and for <code>Extra</code> I need the span to cover the comma because the suggestion cuts out the parameter</p>



<a name="222601470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222601470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222601470">(Jan 13 2021 at 15:52)</a>:</h4>
<p>yeah that does sound tricky unfortunately :/</p>



<a name="222644827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222644827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222644827">(Jan 13 2021 at 21:00)</a>:</h4>
<p><span class="user-mention silent" data-user-id="328499">Pi Lanningham</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Better.20error.20message.20heuristics.20in.20.20.2371827/near/222591655">said</a>:</p>
<blockquote>
<p>I get made fun of for that at work haha</p>
</blockquote>
<p><span aria-label="slight frown" class="emoji emoji-1f641" role="img" title="slight frown">:slight_frown:</span></p>
<p>A complicated algorithm like this is an absolutely appropriate place to have detailed approach comments.</p>



<a name="222688411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222688411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222688411">(Jan 14 2021 at 08:05)</a>:</h4>
<p><span class="user-mention" data-user-id="125270">@scottmcm</span> yea, it's more playful ribbing, cause I do tend to be very verbose heh</p>



<a name="222688630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222688630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222688630">(Jan 14 2021 at 08:08)</a>:</h4>
<p>I did another round on the error messages; incorporated lots of feedback form the PR, and made the suggestion wording very context sensitive.  I also added a bunch of test cases (I thought through lots of test cases when I wrote the prototype <a href="https://glot.io/snippets/fmxqlb8dct">https://glot.io/snippets/fmxqlb8dct</a>, and so I copied those over, but there are probably plenty rust-specific ones that I'm missing).</p>
<p>Still left to do: all the annoying fiddly span math, plus for some reason <code>&amp;str</code> and <code>&amp;'static str</code> aren't registering as compatible sometimes (except in the happy path), plus probably several rounds of feedback.</p>
<p>I really really appreciate the time that anyone is taking to help with reviewing this :D</p>



<a name="222926591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222926591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222926591">(Jan 15 2021 at 21:17)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> thanks for continuing to help review through many iterations, btw :)</p>



<a name="222926619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/222926619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#222926619">(Jan 15 2021 at 21:17)</a>:</h4>
<p>you're very welcome :)</p>



<a name="223020877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223020877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223020877">(Jan 17 2021 at 03:15)</a>:</h4>
<p>Our story around user visible <code>Ty</code>s isn't amazing, but <code>{}</code> and <code>{:?}</code> do about what you might expect, as you have seen.</p>
<p>For <code>Span</code>s, I try to avoid modifying the <code>lo</code> and <code>hi</code> of them directly, instead using the <code>between</code>/<code>until</code> methods, sometimes doing things like <code>span.shrink_to_hi().until(other_span)</code> to operate on them.</p>
<blockquote>
<p>Any idea what the difference between span_to_string and span_to_snippet are?</p>
</blockquote>
<p>As pointed out, the former is to show the file location of the span, the later is to show the code at that position. You 99% of the time want the later.</p>



<a name="223070795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223070795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223070795">(Jan 18 2021 at 00:06)</a>:</h4>
<p>Oo, thanks for chiming in.  I've got invalid and extra argument suggestions working fairly well, and I'm working on "missing" arguments, where it inserts a suggestion for the argument.  This turns out to be pretty tricky; for example:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">many_args</span><span class="p">(</span><span class="n">a</span>: <span class="kt">i32</span><span class="p">,</span><span class="w"> </span><span class="n">b</span>: <span class="kp">&amp;</span><span class="kt">str</span><span class="p">,</span><span class="w"> </span><span class="n">c</span>: <span class="kp">&amp;</span><span class="kt">str</span><span class="p">,</span><span class="w"> </span><span class="n">d</span>: <span class="kp">&amp;</span><span class="kt">str</span><span class="p">,</span><span class="w"> </span><span class="n">e</span>: <span class="kt">i32</span><span class="p">)</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="n">many_args</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>When suggesting inserting the three missing arguments, you have to take into account that the second 1 isn't meant for the second input, it's meant for the last one.  The current implementation suggests</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">many_args</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="o">&amp;</span><span class="kt">str</span><span class="p">},</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="o">&amp;</span><span class="kt">str</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="o">&amp;</span><span class="kt">str</span><span class="p">});</span><span class="w"></span>
</code></pre></div>
<p>I'm starting to think it might be better to avoid piece-by-piece suggestions, and just construct the final argument call manually and do one replacement suggestion.  That would let me just iterate over each input and append either the source from the existing argument it should come from, or a placeholder of the correct type.</p>
<p><span class="user-mention" data-user-id="119031">@Esteban Küber</span> Thoughts? Is there much value in trying to construct the multi-span suggestion with each individual suggested operation (add this, remove that, swap this, etc.)</p>



<a name="223070990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223070990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223070990">(Jan 18 2021 at 00:10)</a>:</h4>
<p>i.e. I could just do something along the lines of this pseudocode:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">suggested_call</span>:<span class="nb">String</span> <span class="o">=</span><span class="w"> </span><span class="fm">format!</span><span class="p">(</span><span class="s">"{}("</span><span class="p">,</span><span class="w"> </span><span class="n">fn_name</span><span class="p">);</span><span class="w"></span>
<span class="k">for</span><span class="w"> </span><span class="n">input</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">expected_inputs</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">if</span><span class="p">(</span><span class="n">already_provided</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">suggested_call</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="n">existing_expression</span><span class="p">;</span><span class="w"></span>
<span class="w">  </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">suggested_call</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="n">placeholder_text</span><span class="p">;</span><span class="w"></span>
<span class="w">  </span><span class="p">}</span><span class="w"></span>
<span class="w">  </span><span class="k">if</span><span class="w"> </span><span class="o">!</span><span class="n">last_argument</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">suggested_call</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="s">", "</span><span class="p">;</span><span class="w"></span>
<span class="w">  </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="n">suggested_call</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="s">")"</span><span class="p">;</span><span class="w"></span>
<span class="n">err</span><span class="p">.</span><span class="n">span_suggestion</span><span class="p">(</span><span class="n">call_span</span><span class="p">,</span><span class="w"> </span><span class="n">suggested_call</span><span class="p">);</span><span class="w"></span>
</code></pre></div>



<a name="223194305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223194305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223194305">(Jan 19 2021 at 07:30)</a>:</h4>
<p>Ok, I coded this up, but I don't wanna push it without some feedback.  It simplifies the code quite a bit, and always provides solid suggestions with correct commas and such.  Here's an example:</p>
<div class="codehilite"><pre><span></span><code>error[E0059]: multiple arguments to this function are incorrect
  --&gt; $DIR/complex.rs:14:3
   |
LL |   complex(1.0, H {}, &amp;&quot;&quot;, G{}, F::X2, Z {}, X {}, Y {});
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: function defined here
  --&gt; $DIR/complex.rs:11:4
   |
LL | fn complex(_i: u32, _s: &amp;str, _e: E, _f: F, _g: G, _x: X, _y: Y, _z: Z ) {}
   |    ^^^^^^^ -------  --------  -----  -----  -----  -----  -----  ------
help: make these changes
   |
LL |   complex({u32}, &amp;&quot;&quot;, {E}, F::X2, G{}, X {}, Y {}, Z {});
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0059`
</code></pre></div>



<a name="223194344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223194344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223194344">(Jan 19 2021 at 07:31)</a>:</h4>
<p>wow, that looks really good :D</p>



<a name="223194351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223194351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223194351">(Jan 19 2021 at 07:31)</a>:</h4>
<p>(I also disabled the individual issue highlighting in the error temporarily, to focus on the suggestion)</p>



<a name="223194409"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223194409" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223194409">(Jan 19 2021 at 07:32)</a>:</h4>
<p>ok cool, I'll push up the branch so you can peek at all the other test cases I have</p>



<a name="223194462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223194462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223194462">(Jan 19 2021 at 07:33)</a>:</h4>
<p>it <em>does</em> destroy someones formatting, in that if they split the call over multiple lines that gets eliminated, but... <span aria-label="shrug" class="emoji emoji-1f937" role="img" title="shrug">:shrug:</span></p>



<a name="223194529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223194529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223194529">(Jan 19 2021 at 07:34)</a>:</h4>
<p>that seems fine, that's what rustfmt is for</p>



<a name="223194555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223194555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223194555">(Jan 19 2021 at 07:35)</a>:</h4>
<p>speaking of which, how do I tell x.py tidy to ignore the test files? <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span> it keeps failing my commits because of formatting issues in the sample cases, so I've been doing --no-verify to keep moving</p>



<a name="223194646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223194646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223194646">(Jan 19 2021 at 07:36)</a>:</h4>
<p>I'm not sure you can :/</p>



<a name="223194663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223194663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223194663">(Jan 19 2021 at 07:37)</a>:</h4>
<p>there's <a href="https://github.com/rust-lang/rust/pull/77675">https://github.com/rust-lang/rust/pull/77675</a> but it's been in limbo for ages</p>



<a name="223194669"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223194669" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223194669">(Jan 19 2021 at 07:37)</a>:</h4>
<p>and I don't think there's a plan to disable other checks</p>



<a name="223194906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223194906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223194906">(Jan 19 2021 at 07:41)</a>:</h4>
<p>Pushed the changes <a href="https://github.com/rust-lang/rust/pull/71827/files">https://github.com/rust-lang/rust/pull/71827/files</a></p>



<a name="223194974"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223194974" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223194974">(Jan 19 2021 at 07:42)</a>:</h4>
<p>the plumbing is still there to "describe" the changes for someone, I'll add that back in and tweak the wording on messages and stuff tomorrow</p>



<a name="223194996"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223194996" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223194996">(Jan 19 2021 at 07:42)</a>:</h4>
<p>been helping my gf move this weekend, so didn't have much time to work on it <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="223263826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223263826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223263826">(Jan 19 2021 at 17:44)</a>:</h4>
<p><span class="user-mention silent" data-user-id="328499">Pi Lanningham</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Better.20error.20message.20heuristics.20in.20.20.2371827/near/223194462">said</a>:</p>
<blockquote>
<p>it <em>does</em> destroy someones formatting, in that if they split the call over multiple lines that gets eliminated, but... <span aria-label="shrug" class="emoji emoji-1f937" role="img" title="shrug">:shrug:</span></p>
</blockquote>
<p>It is an acceptable problem. Suggestions are desired to be correctly formatted, but not required and as Joshua mentions, that falls (at least for now) under rustfix's responsibility, not rustc's</p>



<a name="223263984"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223263984" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223263984">(Jan 19 2021 at 17:46)</a>:</h4>
<p><span class="user-mention silent" data-user-id="328499">Pi Lanningham</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Better.20error.20message.20heuristics.20in.20.20.2371827/near/223194555">said</a>:</p>
<blockquote>
<p>speaking of which, how do I tell x.py tidy to ignore the test files? <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span> it keeps failing my commits because of formatting issues in the sample cases, so I've been doing --no-verify to keep moving</p>
</blockquote>
<p>I'm pretty sure <code>// ignore-tidy-CHECK_NAME</code> works on tests too (but didn't see an example)<br>
<a href="https://github.com/rust-lang/rust/blob/6bfe27a3e0f1c4d77999ccc2350ab861327615a2/src/tools/tidy/src/style.rs">https://github.com/rust-lang/rust/blob/6bfe27a3e0f1c4d77999ccc2350ab861327615a2/src/tools/tidy/src/style.rs</a></p>



<a name="223268703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223268703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223268703">(Jan 19 2021 at 18:17)</a>:</h4>
<p><span class="user-mention" data-user-id="119031">@Esteban Küber</span> one open question you could help with is here: <a href="https://github.com/rust-lang/rust/pull/71827/files#diff-c959e329c9086f50cf2fb291795e70282db511be82655cd70c555d101818e036R248-R253">https://github.com/rust-lang/rust/pull/71827/files#diff-c959e329c9086f50cf2fb291795e70282db511be82655cd70c555d101818e036R248-R253</a></p>
<p>Summary: I have <code>demand_compatible</code>, which writes typecheck obligations and is only invoked on the "happy path", and <code>check_compatible</code> which is supposed to typecheck without writing back those obligations.  The way I found to do that previously was having trouble checking <code>""</code>, so I found this new way, and I want to make sure it's not going to cause issues.</p>



<a name="223271559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223271559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223271559">(Jan 19 2021 at 18:34)</a>:</h4>
<p>IIRC, calling <code>check_compatible</code> is the right thing to do here, <span class="user-mention" data-user-id="328499">@Pi Lanningham</span></p>



<a name="223272246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/223272246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#223272246">(Jan 19 2021 at 18:38)</a>:</h4>
<p>er, check_compatible is my function, the question is should I be using             <code>self.check_expr_kind(provided_arg, expectation);</code></p>



<a name="225383601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/225383601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#225383601">(Feb 06 2021 at 03:26)</a>:</h4>
<p><span class="user-mention" data-user-id="119031">@Esteban Küber</span> <span class="user-mention" data-user-id="232545">@Joshua Nelson</span> Sorry guys, this went on the back burner for a few weeks, but I'm ready to try to move towards wrapping it up.</p>
<p>In the current state, this code flags the method call as an error, then suggests one complete replacement with missing, extra, and swapped arguments substituted. ex:</p>
<div class="codehilite"><pre><span></span><code>error[E0059]: multiple arguments to this function are incorrect
  --&gt; $DIR/complex.rs:14:3
   |
LL |   complex(1.0, H {}, &amp;&quot;&quot;, G{}, F::X2, Z {}, X {}, Y {});
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: function defined here
  --&gt; $DIR/complex.rs:11:4
   |
LL | fn complex(_i: u32, _s: &amp;str, _e: E, _f: F, _g: G, _x: X, _y: Y, _z: Z ) {}
   |    ^^^^^^^ -------  --------  -----  -----  -----  -----  -----  ------
help: make these changes
   |
LL |   complex({u32}, &amp;&quot;&quot;, {E}, F::X2, G{}, X {}, Y {}, Z {});
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0059`.
</code></pre></div>
<p>Couple of remaining questions:</p>
<ul>
<li>It's missing the per-argument annotations to explain what the changes were that it used to have.  Do we think those would still be valuable?</li>
<li>if yes, in all cases?</li>
<li>if not in all cases, what heuristics would make sense for switching from individual suggestions to "it's all broke, fix it"?</li>
<li>The wording "make these changes" doesn't sit well with me, anyone have ideas for a better suggestion text?</li>
</ul>



<a name="225383696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/225383696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#225383696">(Feb 06 2021 at 03:28)</a>:</h4>
<p>You could show the missing info as labels in the main diagnostic. As a heuristic you could say anything beyond 5 individual pieces of info we just say "things are hella broken, mate"</p>



<a name="225383718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/225383718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#225383718">(Feb 06 2021 at 03:29)</a>:</h4>
<p>Don't tempt me, I might literally put that :P</p>



<a name="225383769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/225383769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#225383769">(Feb 06 2021 at 03:30)</a>:</h4>
<p>For the suggestion wording... It's tricky. I would probably have put a placeholder of "consider making the following changes"</p>



<a name="225383794"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/225383794" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#225383794">(Feb 06 2021 at 03:30)</a>:</h4>
<p>That's close to what I had before, but one reviewer suggested more affirmative wording, since the fact that it's a suggestion already makes it clear that it's optional</p>



<a name="225384178"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/225384178" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#225384178">(Feb 06 2021 at 03:39)</a>:</h4>
<p>Yeah</p>



<a name="225384180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/225384180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#225384180">(Feb 06 2021 at 03:39)</a>:</h4>
<p>It's hard</p>



<a name="225384239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/225384239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#225384239">(Feb 06 2021 at 03:41)</a>:</h4>
<p>What about "use the arguments of the correct type" or "use appropriate arguments"</p>



<a name="225384269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/225384269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#225384269">(Feb 06 2021 at 03:41)</a>:</h4>
<p>Also, I would see if we can make the suggestion span point at the arguments within the parens, to try and make it clearer if possible that that's the only thing changing</p>



<a name="225384415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/225384415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#225384415">(Feb 06 2021 at 03:45)</a>:</h4>
<p>I can try that.  If I have a PR up tonight, would you be free to review it tomorrow?</p>



<a name="225385835"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/225385835" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#225385835">(Feb 06 2021 at 04:21)</a>:</h4>
<p>Other options:</p>
<ul>
<li>"did you mean"</li>
<li>"did you mean this argument ordering"</li>
<li>"arguments may be out of order"</li>
<li>"arguments may be in the wrong order"</li>
<li>"try reordering arguments"</li>
</ul>



<a name="225385962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/225385962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#225385962">(Feb 06 2021 at 04:25)</a>:</h4>
<p>"did you mean" might work, but the doc comment on <code>span_suggestion</code> (compiler/rustc_errors/src/diagnostic.rs) explicitly calls out "did you mean" as something to avoid</p>
<p>the rest don't work because the suggestions include a variety of things, not just reordering</p>



<a name="225386018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/225386018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#225386018">(Feb 06 2021 at 04:26)</a>:</h4>
<blockquote>
<p>"did you mean" might work, but the doc comment on span_suggestion (compiler/rustc_errors/src/diagnostic.rs) explicitly calls out "did you mean" as something to avoid</p>
</blockquote>
<p>Perhaps, but there are already several suggestions that use "did you mean", and I agree that "make these changes" doesn't sound right.</p>



<a name="225386047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/225386047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#225386047">(Feb 06 2021 at 04:27)</a>:</h4>
<p>I haven't looked at the code much; is there a way to know which changes have been applied and use a specific message?</p>



<a name="225386066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/225386066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#225386066">(Feb 06 2021 at 04:29)</a>:</h4>
<p>I can ladder up the language, but at the top, when multiple suggestions are mixed, I still need some generic language.  Like, I can say "if the <em>only</em> suggestion here is swapped arguments, use "swap these arguments", and if the only suggestion is invalid types, use "fix these types"", but when both of them are combined I need to know what to say</p>



<a name="225387116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/225387116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#225387116">(Feb 06 2021 at 05:01)</a>:</h4>
<p>Running --bless on all the tests now <span aria-label="fingers crossed" class="emoji emoji-1f91e" role="img" title="fingers crossed">:fingers_crossed:</span> <span aria-label="scream" class="emoji emoji-1f631" role="img" title="scream">:scream:</span></p>



<a name="225425273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/225425273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#225425273">(Feb 06 2021 at 18:57)</a>:</h4>
<p>The blessing turned out to be way more involved than previously expected lol.  And there's some corner cases that I'll need help resolving ("expected Struct X" vs "expected X", etc.)</p>



<a name="225440239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/225440239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#225440239">(Feb 07 2021 at 01:56)</a>:</h4>
<p>"swap these arguments and fix these types"? <span aria-label="wink" class="emoji emoji-1f609" role="img" title="wink">:wink:</span></p>



<a name="225448503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/225448503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pi Lanningham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#225448503">(Feb 07 2021 at 06:30)</a>:</h4>
<p>Pushed up <a href="https://github.com/rust-lang/rust/pull/71827/commits/52672859a031e2c749e11c80b3a8727c781edbc5">a commit</a> where I --bless'd the error messages.  Some remaining issues, which I could use some help with:</p>
<ul>
<li>
<p>Pretty confused as to what error codes I should use; should I use a new one, since the error message is different? should I try to map the cases onto existing error codes? etc.</p>
</li>
<li>
<p>Lots of "descriptive" corner cases my code falls down on; sometimes it comes up with a type <code>_</code>, when the previous code suggested a good type, or it's missing descriptive keywords like <code>struct</code>, etc.</p>
</li>
<li>
<p>Some weird corner cases around inferred associated types, interestingly the suggestions are good, but the error message highlighting it is odd</p>
</li>
<li>
<p>Lots of regressions on corner case suggestions for some reason, like "consider borrowing", "consider deref", etc.  I didn't see that in the original code, so I'm not sure how I deflected things downstream such that those suggestions aren't showing up.</p>
</li>
</ul>



<a name="234573575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/234573575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#234573575">(Apr 14 2021 at 20:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="255061">Léo Lanteri Thauvin</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Better.20error.20message.20heuristics.20in.20.20.2371827/near/221424137">said</a>:</p>
<blockquote>
<blockquote>
<p>those don't look particularly helpful, since BytePos doesn't implement mathematical operators</p>
</blockquote>
<p><code>BytePos</code> does implement <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.BytePos.html#impl-Add%3CBytePos%3E-1"><code>+</code></a> and <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.BytePos.html#impl-Sub%3CBytePos%3E-1"><code>-</code></a> though</p>
<p>hmm, that only works if you already have a BytePos though</p>
</blockquote>



<a name="234573592"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Better%20error%20message%20heuristics%20in%20%20%2371827/near/234573592" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Better.20error.20message.20heuristics.20in.20.20.2371827.html#234573592">(Apr 14 2021 at 20:58)</a>:</h4>
<p>I have one bytepos and one usize</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>